package leetcode;

import util.TreeNode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0538.java
 * @Author : WangRuoyu
 * @Date 2023/11/16 15:58
 */


public class Q0538 {
    private int dfs(TreeNode node, int sum) {
        if (node == null) return sum;
        node.val += dfs(node.right, sum);
        return dfs(node.left, node.val);
    }

    public TreeNode convertBST(TreeNode root) {
        dfs(root, 0);
        return root;
    }

    public static void main(String[] args) {
        Q0538 sl = new Q0538();
    }
}